package bubbleindex;

import java.awt.Component;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JOptionPane;

/**
 *
 * @author ttrott
 */
public class Errors {
    
    private static Component frame;
    
    /*
     * invalidInputFile displayed if the daily price data file contains non numeric values
     */
    public static void invalidInputFile() {
        BuildIndex.Stop = true;
        JOptionPane.showMessageDialog(frame, "Invalid Data. Make sure file is correctly formatted.");
    }
    
    /*
     * failedToReadFile displayed if the file read process failed for any reason
     */
    public static void failedToReadFile() {
        BuildIndex.Stop = true;
        JOptionPane.showMessageDialog(frame, 
                "Failed to read the input file. Make sure file is correclty formatted.");
    }
    
    /*
     * interruptedExecution displayed if bubbleindex create process is interrupted
     */
    public static void interruptedExecution() {
        BuildIndex.Stop = true;
        JOptionPane.showMessageDialog(frame, "Execution Error.");
    }
    
    /*
     * invalidGUIInputs displayed if values inputted into the GUI are invalid
     */
    public static void invalidGUIInputs() {
        BuildIndex.Stop = true;
        JOptionPane.showMessageDialog(frame, "Invalid model parameters.");        
    }

    /*
     * failedToWriteFile displayed if failure occurs during the file write process
     * @param writer the filewriter stream to flush and close upon error
     */
    public static void failedToWriteFile(FileWriter writer ) throws IOException {
        BuildIndex.Stop = true;
        writer.flush();
        writer.close();
        JOptionPane.showMessageDialog(frame, "Failed to write output file.");        
    }

    public static void failedToCreateFile() throws IOException {
        BuildIndex.Stop = true;
        JOptionPane.showMessageDialog(frame, "Failed to write output file.");        
    }
    
    /*
     * failedToReadIndices displayed if the list files containing the names are null
     */
    /*
    public static void failedToReadIndices() {
        Indices.IndicesNamesArray = new String[1];
        Indices.StocksNamesArray = new String[1];
        Indices.CommoditiesNamesArray = new String[1];
        Indices.CurrenciesNamesArray = new String[1];
        JOptionPane.showMessageDialog(frame, 
                "Failed to input indices. Make sure the files are correclty formatted.");        
    }
    */
}